package cn.itcast.item.controller;


import cn.itcast.hmall.dto.common.ResultDTO;
import cn.itcast.item.pojo.Item;
import cn.itcast.item.pojo.Req;
import cn.itcast.item.service.ItemService;
import cn.itcast.item.vo.PageDTO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/item")
public class ItemController {

    @Autowired
    private ItemService itemService;

    @PostMapping("/list")
    public PageDTO pageQuery(@RequestBody Req req) {
        return itemService.getList(req);
    }

    @GetMapping("/{id}")
    public Item getItemById(@PathVariable("id") Long id) {
        return itemService.getById(id);
    }

    @PostMapping
    public ResultDTO addItem(@RequestBody Item item) {
        return itemService.muSave(item);
    }

    @PutMapping("/status/{id}/{status}")
    public ResultDTO itemUpDown(@PathVariable("id")Long id,
                                @PathVariable("status")int status){
        return itemService.myUpdateById(id,status);
    }

    @PutMapping
    public ResultDTO updateItem(@RequestBody Item item){
        return itemService.myUpdateById(item);
    }

    @DeleteMapping("/{id}")
    public ResultDTO deleteItem(@PathVariable("id")Long id){
        return itemService.myDeleteById(id);
    }
}
